package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.util.GlideCircleTransform;
import com.ly.lypopupwindowdemo.util.GlideRotateTransform;
import com.ly.lypopupwindowdemo.util.GlideRoundTransform;
import com.ly.lypopupwindowdemo.util.IntentUtil;
import com.ly.lypopupwindowdemo.util.LException;
import com.squareup.picasso.Picasso;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CameraActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * Picasso 框架加载图片详解
     * http://bbs.itcast.cn/thread-87019-1-1.html
     * http://bbs.itcast.cn/thread-87019-1-1.html
     * http://bbs.itcast.cn/thread-87019-1-1.html
     */

    private ImageView iv;
    private static final String TAG = "CameraActivity";

    private Button btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);

        iv = (ImageView) findViewById(R.id.iv);
        btn = (Button) findViewById(R.id.btn1);
        btn.setOnClickListener(this);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode!=RESULT_OK){
            return;
        }else{
            if (data!=null){
                String image_path = data.getStringExtra("image_path");
                if (requestCode==101){

                    /**
                     * Glide加载图片 nice
                     * http://www.jianshu.com/p/cea08d72ad4c
                     * http://www.jianshu.com/p/cea08d72ad4c
                     * http://www.jianshu.com/p/cea08d72ad4c
                     *
                     * http://www.jianshu.com/p/936efd25f75c
                     * http://www.jianshu.com/p/936efd25f75c
                     */
                    File file = new File(image_path);
                    //Picasso 加载图片
                    //Picasso.with(this).load(file).into(iv);
                    //Glide加载图片
                    //Glide.with(this).load(file).into(iv);
                    //剪裁成圆角图片
                    //Glide.with(this).load(file).centerCrop().transform(new GlideRoundTransform(this,50)).into(iv);
                    //剪裁圆形图片
                    Glide.with(this).load(file).transform(new GlideCircleTransform(this)).into(iv);
                    //Glide旋转图片
                   // Glide.with(this).load(file).centerCrop().transform(new GlideRotateTransform(this)).into(iv);
                }
            }
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn1:
                //打开相册
                try {
                    IntentUtil.startGetpic(CameraActivity.this,101);
                } catch (LException e) {
                    e.printStackTrace();
                }
                break;
        }
    }
}
